function [F,w]=ffft(f,a,b,N,c,d,M)
% function:
%        ffft
% input:
%        f : vector, (N+1) samples on a function;
%        a, b, N: partition of time domain
%        c, d, M: partition of frequency domain
% output:
%        F: vector, values of Ff on w;
%        w: vector;
% Call: (none)
% 
%----------------------------------------
% Principle: the general form of fft
% Application: FT of functions on R
% Assertion: d-c<=N/(b-a)
% Example: 
% See also fft czt
%----------------------------------------
% Author: William
% Date: 16-Nov-2009

if nargin<=6
    if nargin<=4
        c=0;d=10;
        if nargin<=1
            a=0;b=1;N=100;
        end
    end
    M=N;
end

n=(b-a)/N; m=(d-c)/M;           % step length

F=czt(f, M, exp(-2i*pi*n*m), exp(2i*pi*n*c));
F=n*F.*exp(-2i*pi*a*(c:m:(d-m)));

if nargout==2
    w=linspace(c, d, M+1);
    w(M+1)=[];
end